package com.dhcc.frame.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class ThreadPoolTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
//		//3个线程  10个任务  每个任务打印10条信息
//		ExecutorService threadPool = Executors.newFixedThreadPool(3);
//		//缓存线程池(线程随着任务)
////		ExecutorService threadPool = Executors.newCachedThreadPool();
//		//单线程池(池里始终有一个线程，如果线程死了马上创建一个替补线程)
////		ExecutorService threadPool = Executors.newSingleThreadExecutor();
//		for(int i=1;i<=10;i++){
//			final int task = i;
//			threadPool.execute(new Runnable(){
//				@Override
//				public void run() {
//					for(int i=1;i<=10;i++){
//						try {
//							Thread.sleep(20);
//						} catch (InterruptedException e) {
//							e.printStackTrace();
//						}
//						System.out.println(Thread.currentThread().getName() + " is looping of " + i + " for  task of " + task);
//					}
//				}
//			});
//		}
//		System.out.println("all of 10 tasks have committed! ");
//		threadPool.shutdownNow();

		//调度线程池
//		Executors.newScheduledThreadPool(3).schedule(command, delay, unit);
		//调度线程池
		Executors.newScheduledThreadPool(3).scheduleAtFixedRate(
				new Runnable(){
					@Override
				public void run() {
					System.out.println("bombing!");

				}},
				6,
				2,
				TimeUnit.SECONDS);
	}

}
